"""
Case Type   : 功能测试
Case Name   : add_months函数边界值校验
Create At   : 2021-01-11
Owner       : opentestcase006
Description : add_months(d,n)描述：用于计算时间点d再加上n个月的时间。
    1. 参数2给边界值3531312
    2. 参数2给超过边界值3531313
Expect      : 
    1. 正常转换
    2. 提示报错
History     :
    modified by nanyang12 2024/12/6:date类型适配A兼容性，取值范围变更（year must be between -4712 and 9999, and not be 0），修改预期适配最新代码
"""

import unittest
from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import CommonSH

LOG = Logger()


class Function(unittest.TestCase):

    def setUp(self):
        LOG.info("Opengauss_Function_Innerfunc_Add_Months_Case0015开始")
        self.commonsh = CommonSH('dbuser')

    def test_add(self):  # 结果不能超过294277-01-09

        sql_cmd = """select add_months('294277-01-09','0');
                     select add_months('0001-01-01','3531313');
                     select add_months('294277-01-09','1');"""
        msg1 = self.commonsh.execut_db_sql(sql_cmd)
        LOG.info(msg1)
        flag1 = msg1.count(
            'ERROR:  invalid data for "year =  294277", value must be between -4712 and 9999, and not be 0') == 2
        self.assertTrue(flag1)
        flag = msg1.count('ERROR:  timestamp out of range') == 1
        self.assertTrue(flag)

    def tearDown(self):
        LOG.info("Opengauss_Function_Innerfunc_Add_Months_Case0015结束")
